using System.Windows.Controls;
using System.Windows.Input;

namespace Wintellect.Touch
{
    /// <summary>
    /// <see cref="ComboBoxItem"/> override to prevent default behavior for MouseLeftButtonUp to close the ComboBox, 
    /// which prevents selection in the <see cref="TouchableComboBox"/>
    /// </summary>
    internal class TouchableComboBoxItem : ComboBoxItem
    {
        /// <summary>
        /// Provides handling for the <see cref="E:System.Windows.UIElement.MouseLeftButtonUp"/>event.
        /// </summary>
        /// <param name="e">The event data.</param>
        protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        {
            // See explanation, below.
            //e.Handled = true;
            //base.OnMouseLeftButtonUp(e);
        }

        // The base ComboBoxItem behavior for MouseLeftButtonUp is to close the combo box.
        // Setting the event to handled or skipping the base call entirely (as above) bypasses this behavior.
        //protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
        //{
        //    if (e == null)
        //    {
        //        throw new ArgumentNullException("e");
        //    }
        //    if (!e.Handled)
        //    {
        //        base.OnMouseLeftButtonUp(e);
        //        e.Handled = true;
        //        ComboBox box = base._parentSelector as ComboBox;
        //        if (box != null)
        //        {
        //            box.IsDropDownOpen = false;
        //        }
        //    }
        //}
    }
}